package com.xyh.student.controller;


import com.xyh.student.entity.ResponseData;
import com.xyh.student.entity.Teacher;
import com.xyh.student.service.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
@RequestMapping("/Teacher")
public class TeacherController {
    @Autowired
    private TeacherService teacherService;

    //查询所有老师信息
    //http://localhost:8081/Teacher/queryAllTeacher
    @GetMapping("/queryAllTeacher")
    @ResponseBody
    public ResponseData queryAllTeacher(Integer pageNum, Integer pageSize){
        int start=(pageNum-1)*pageSize;
        return this.teacherService.queryAllTeacher(start,pageSize);
    }

    //通过sid查询目标老师的信息
    //http://localhost:8081/Teacher/queryByid/{id}
    @GetMapping("/queryByid/{id}")
    @ResponseBody
    public ResponseData queryByid(@PathVariable("id") Integer id){
        return this.teacherService.queryByid(id);
    }

    //增加一个老师
    //http://localhost:8081/Teacher/insertTeacher
    @PostMapping("/insertTeacher")
    @ResponseBody
    public ResponseData insertTeacher(@RequestBody Teacher teacher){
        return this.teacherService.insertTeacher(teacher);
    }

    //更新数据
    //http://localhost:8081/Teacher/updateTeacher
    @PostMapping("/updateTeacher")
    @ResponseBody
    public ResponseData updateTeacher(@RequestBody Teacher teacher){
        return this.teacherService.updateTeacher(teacher);
    }

    // 通过id删除目标老师的信息
    //http://localhost:8081/Teacher/deleteTeacherByid/{id}
    @DeleteMapping("/deleteTeacherByid/{id}")
    @ResponseBody
    public ResponseData deleteTeacherByid(@PathVariable("id") Integer id){
        return this.teacherService.deleteTeacherByid(id);
    }

    //批量删除老师信息
    //http://localhost:8081/Teacher/deletes
    @DeleteMapping("deletes")
    @ResponseBody
    public ResponseData deletes(int[] ids){
        return this.teacherService.deletes(ids);
    }


    //获得老师数量
    //http://localhost:8081/Teacher/numberOfTeachers
    @GetMapping("/numberOfTeachers")
    @ResponseBody
    public ResponseData numberOfTeachers(){
        return this.teacherService.numberOfTeachers();
    }

    //用户注册
    //http://localhost:8081/Teacher//userRegister
    @PostMapping("/userRegister")
    @ResponseBody
    public ResponseData userRegister(@RequestBody Teacher user){
        System.out.println("user = "+user);
        return teacherService.userRegister(user);
    }

    //用户登录
    //http://localhost:8081/Teacher/userLogin
    @PostMapping("/userLogin")
    @ResponseBody
    public ResponseData userLogin(String name,String password){

        return teacherService.userLogin(name,password);
    }

    //通过用户姓名查找
    //http://localhost:8081/Teacher/queryUserByUserName
    @GetMapping("/queryUserByUserName")
    @ResponseBody
    public ResponseData queryUserByUserName(String name){
        return this.teacherService.queryUserByUserName(name);
    }
    //通过密码查找
    //http://localhost:8081/Teacher/queryUserBypassword
    @GetMapping("/queryUserBypassword/{password}")
    @ResponseBody
    public ResponseData queryUserBypassword(@PathVariable("password") String password){
        return this.teacherService.queryUserBypassword(password);
    }


}
